package com.example.controller;

import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.wml.Body;
import org.docx4j.wml.Document;

import java.io.File;

public class CreateDocxWithContent {

    public static void main(String[] args) throws Exception {
        // 1. 创建一个新的Word文档包
        WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
        MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart();

        // 2. 添加一级标题
        Document contents = mainDocumentPart.getContents();
        contents.setBody(new Body());

        // 3. 添加普通内容段落

        // 4. 添加二级标题

        // 5. 添加带样式的内容段落

        // 6. 添加三级标题

        // 7. 添加另一段内容

        // 8. 保存文档
        String outputPath = "D:/权限管理表.docx";
        wordMLPackage.save(new File(outputPath));
        System.out.println("文档已成功创建：" + new File(outputPath).getAbsolutePath());
    }


}
